﻿using System;
using System.Windows.Data;

namespace Rio.Framework.Pages.Helpers
{
    public class ImageRioPropertyToFriendlyDisplayConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            object returnValue = null;

            switch ((parameter as string).ToLowerInvariant())
            {
                case "author":
                    string author = System.Convert.ToString(value);
                    returnValue = String.IsNullOrWhiteSpace(author) ? "-" : author;
                    break;
                case "lastmodificationauthor":
                    if (value == null)
                    {
                        returnValue = "-";
                    }
                    else
                    {
                        returnValue = value;
                    }
                    break;
                case "dimension":
                    if (value == null)
                    {
                        returnValue = "-";
                    }
                    else
                    {
                        returnValue = value;
                    }
                    break;
                case "resolution":
                    if (value == null)
                    {
                        returnValue = "-";
                    }
                    else
                    {
                        returnValue = value;
                    }
                    break;
                case "numberpages":
                    int numberPages = System.Convert.ToInt32(value);
                    if (numberPages > 0)
                    {
                        returnValue = value;
                    }
                    else
                    {
                        returnValue = "-";
                    }
                    break;
                default:
                    returnValue = value;
                    break;
            }

            return returnValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
